package org.advanced.base;

import java.util.concurrent.TimeUnit;

/**
 * @author John.zhang
 * @version Id: ThreadStatus, v 1.0 2020/12/7 14:44 ZhiYong Exp $
 * 打开包class  open in terminal -jps查看进程  -jstack 21452
 */
public class ThreadStatus {

    public static void main(String[] args) {
        //TIME_WAITING
        new Thread(()->{
            while (true){
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"TIME_WAITING").start();

        //WAITING
        new Thread(()->{
            while (true){
                synchronized (ThreadStatus.class){
                    try {
                        ThreadStatus.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"WAITING").start();


        new Thread(new Blocked(),"Blocked-01").start();
        new Thread(new Blocked(),"Blocked-02").start();

    }

    static class Blocked extends Thread {

        @Override
        public void run() {
            synchronized (Blocked.class){
                while (true){
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

}
